package com.cookie; /**
 * @author wzm
 * @create 2023-03-13 11:23
 */

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/cookie01")
public class CookieServlet01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html;charset=utf-8");

        //创建Cookie对象 并且通过构造方法存值
        Cookie cookie = new Cookie("username","zs");
        Cookie cookie1 = new Cookie("password","123456");

        //通知浏览器保存创建的Cookie
        response.addCookie(cookie);

        response.getWriter().write("创建Cookie成功");



    }
}
